﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public static class AdDB
    {
        public static List<WorkAds> GetWorkAds()
        {
            return Model.GetContext().WorkAdsSets.ToList();
        }

        public static int GetExpiredAdsCount()
        {
            return Model.GetContext().WorkAdsSets
                .ToList().Where(x => 
                    x.ExpiredDate.AddDays(14) >= DateTime.Now && !x.Deleted).Count();
        }

        public static void DeleteExpiredAds()
        {
            var expiredAds = 
                Model.GetContext().WorkAdsSets.ToList()
                .Where(x => 
                    x.ExpiredDate.AddDays(14) >= DateTime.Now && !x.Deleted);

            foreach (var ad in expiredAds)
            {
                ad.Deleted = true;
            }
            System.Diagnostics.Debug.Print("Deleted: " + Model.GetContext().SaveChanges().ToString());
        }
    }
}
